﻿using Microsoft.AspNetCore.Mvc;
using Dapper.Sharding.CAP;
using System.Text.Json;

namespace TestWeb1.Controllers
{
    [Route("[controller]/[action]")]
    public class HomeController : ControllerBase
    {
        public IActionResult Index()
        {
            var token = Request.Query["token"];
            var actorPath = Request.Query["actorPath"];

            var tran = new DistributedTransactionCap(MyCap.Cap, token, actorPath, "t1");
            try
            {
                var data = JsonSerializer.Serialize(tran.TranMsg);
                DbContext.People.Insert(new PeopleTable { Name = data }, tran);
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                Console.WriteLine(ex.Message);
            }
            return Content("ok");
        }
    }
}
